<?php

class Emms_Form_Admin_Program extends HTech_Form
{
    protected $_primary  = 'ProgramId';
    
    public function __construct() 
    {
        parent::__construct();
        
        $this->setName('Program');
                
        $this->setAttrib('title', $this->translate("Program form"));
        $this->setDescription($this->translate("Edit program info or add a new one"));
                
        $programId = new Zend_Form_Element_Hidden('ProgramId');
        
        $program = new Zend_Form_Element_Text('Program');
        $program->setLabel("Program")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Alnum', array('allowwhitespace' => true))
            ->addValidator('StringLength',false,
                array(
                    'min'      => 2,
                    'max'      => 64,
                    'messages' => $this->translate("From %min% to %max% characters only")
                ))
            ->addValidator('Db_NoRecordExists',false,
                array(
                    'table'    => 'programs', 
                    'field'    => 'Program', 
                    'exclude'  => array('field' => 'ProgramId', 'value' => $this->_id),
                    'messages' => $this->translate("Non valid or duplicated entry")                    
                ))
            ->setDescription(null);
                
        $fundId = new Zend_Form_Element_Multiselect('LnkProgramsFunds');
        $fundId->setLabel("Funds - press Ctrl key for multiple selection")                
            ->setAttrib('size','6')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions($this->_db->fetchPairs('select FundId, Fund from funds'));    
                
        $productLineId = new Zend_Form_Element_Select('ProductLineId');
        $productLineId->setLabel("Product line")                
            ->setAttrib('size','3')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions($this->_db->fetchPairs('select ProductLineId, ProductLine from product_lines'));     
                
        $surveyId = new Zend_Form_Element_Select('SurveyId');
        $surveyId->setLabel("Survey")                
            ->setAttrib('size','3')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions($this->_db->fetchPairs('select SurveyId, Name from surveys'));          
        
        $business = new Zend_Form_Element_Select('Business');
        $business->setLabel("Business")                
            ->setAttrib('size','2')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions(array('Yes' => $this->translate("Yes"), 'No' => $this->translate("No")));           
        
        $locationId = new Zend_Form_Element_Multiselect('LnkLocationsPrograms');
        $locationId->setLabel("Locations - press Ctrl key for multiple selection")                
            ->setAttrib('size','6')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions($this->_db->fetchPairs('select LocationId, Name from locations where Category != "Center"'));          
        
        $status = new Zend_Form_Element_Select('Status');
        $status->setLabel("Status")                
            ->setAttrib('size','2')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions(array('Active' => $this->translate("Active"), 'Inactive' => $this->translate("Inactive")));   
                
        $publicSponsorship = new Zend_Form_Element_Select('PublicSponsorship');
        $publicSponsorship->setLabel("Public sponsorship")                
            ->setAttrib('size','2')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions(array('Yes' => $this->translate("Yes"), 'No' => $this->translate("No")));         
                        
        $comments = new Zend_Form_Element_Textarea('Comments');
        $comments->setLabel("Comments")
            ->addFilter('Alnum', array('allowwhitespace' => true))
            ->setAttrib('rows', 4); 
        
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Submit")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type'=>'submit')));
        
        $this->addElements(array($program,$fundId,$productLineId,$surveyId,$business,$locationId,$status,$publicSponsorship,$comments,$submit,$programId));
    }
}